package com.ph.irp.base.assistantmaterial.service.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.ph.exception.PHException;
import com.ph.irp.base.assistantmaterial.dao.PBaseAssistantmaterialSuppliercategoryDao;
import com.ph.irp.base.assistantmaterial.service.PBaseAssistantmaterialSuppliercategoryService;

import com.ph.irp.model.PBaseAssistantmaterialSuppliercategory;

public class PBaseAssistantmaterialSuppliercategoryServiceImpl implements
		PBaseAssistantmaterialSuppliercategoryService {
	// 供应商分类dao
	private PBaseAssistantmaterialSuppliercategoryDao suppliercategoryDao = null;
	// 供应商分类List
	private List<PBaseAssistantmaterialSuppliercategory> suppliercategoryList = null;
	// 供应商分类Model
	private PBaseAssistantmaterialSuppliercategory suppliercategoryModel = null;

	@Override
	/**
	 * 增加供应商类别信息
	 */
	public void addAssistantmatteialSuppliercategory(
			PBaseAssistantmaterialSuppliercategory suppliercategoryModel)
			throws Throwable {

//		try {
//			if (this.suppliercategoryDao.isSameCode(suppliercategoryModel
//					.getSupplierCategoryCode())) {
//				throw new PHException("供应商类别代码"
//						+ suppliercategoryModel.getSupplierCategoryCode()
//						+ "已经存在");
//			} else if (this.suppliercategoryDao
//					.isSameName(suppliercategoryModel.getSupplierCategoryName())) {
//				throw new PHException("供应商类别名称"
//						+ suppliercategoryModel.getSupplierCategoryName()
//						+ "已经存在");
//			} else {
//				try {
//					this.suppliercategoryDao
//							.addSuppliercategory(suppliercategoryModel);
//				} catch (SQLException e) {
//					throw new PHException("添加供应商类别异常");
//
//				}
//			}
//		} catch (SQLException e) {
//			throw new PHException("添加供应商类别异常");
//		}
		this.suppliercategoryDao.addSuppliercategory(suppliercategoryModel);
	}

	/**
	 * 删除供应商类别信息
	 * @throws Throwable 
	 */
	@Override
	public void deleteAssistantmateialSuppliercategory(
			Object[] suppliercategoryIds) throws Throwable {
//		try {
//			this.suppliercategoryDao
//					.deleteSuppliercategoryById(suppliercategoryIds);
//		} catch (SQLException e) {
//			throw new PHException("信息存在被其他条目引用不能删除，请确认后操作");
//		}
		this.suppliercategoryDao.deleteSuppliercategoryById(suppliercategoryIds);
	}

	@Override
	public List<PBaseAssistantmaterialSuppliercategory> getALLAssistantmaterialSuppliercategory()
			throws Throwable {
//
//		try {
//			List<PBaseAssistantmaterialSuppliercategory> suppliercategoryList = suppliercategoryDao
//					.getALLSuppliercategory();
//		} catch (SQLException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
		List<PBaseAssistantmaterialSuppliercategory> suppliercategoryList = suppliercategoryDao.getALLSuppliercategory();
		return suppliercategoryList;
	}

	@Override
	public List<PBaseAssistantmaterialSuppliercategory> getAssistantmaterialSuppliercategory(
			PBaseAssistantmaterialSuppliercategory suppliercategoryModel)
			throws Throwable {
		List<PBaseAssistantmaterialSuppliercategory> suppliercategoryList = null;
		if (suppliercategoryModel == null) {
		//	try {
				suppliercategoryList = suppliercategoryDao
						.getALLSuppliercategory();
			//} catch (SQLException e) {
			//	throw new PHException("查询异常");
			//}
		}

		else {
			if (!(suppliercategoryModel.getSupplierCategoryCode().trim()
					.equals(""))
					&& !(suppliercategoryModel.getSupplierCategoryName().trim()
							.equals(""))) {
			//	try {
					suppliercategoryList = suppliercategoryDao
							.getSuppliercategoryByCodeAndName(
									suppliercategoryModel
											.getSupplierCategoryCode(),
									suppliercategoryModel
											.getSupplierCategoryName());
				//} catch (SQLException e) {
				//	throw new PHException("查询异常");
				//}
			} else if (!suppliercategoryModel.getSupplierCategoryCode().trim()
					.equals("")) {
				//try {
					suppliercategoryList = suppliercategoryDao
							.getSuppliercategoryByCode(suppliercategoryModel
									.getSupplierCategoryCode());
			//	} catch (SQLException e) {
				//	throw new PHException("查询异常");
				//}
			} else if (!suppliercategoryModel.getSupplierCategoryName().trim()
					.equals("")) {
				//try {
					suppliercategoryList = suppliercategoryDao
							.getSuppliercategoryByName(suppliercategoryModel
									.getSupplierCategoryName());
				//} catch (SQLException e) {
				//	throw new PHException("查询异常");
				//}
			} else
				//try {
					suppliercategoryList = suppliercategoryDao
							.getALLSuppliercategory();
				//} catch (SQLException e) {
					// TODO Auto-generated catch block
				//	throw new PHException("查询异常");
				//}
		}
		return suppliercategoryList;

	}

	/**
	 * 根据Id查找行业信息
	 * @throws Throwable 
	 */
	@Override
	public PBaseAssistantmaterialSuppliercategory getAssistantmaterialSuppliercategoryById(
			int suppliercategoryId) throws Throwable {

		return this.suppliercategoryDao	.getSuppliercategoryById(suppliercategoryId);
	}
	

	public List<PBaseAssistantmaterialSuppliercategory> getAssistantmaterialSuppliercategoryByCode(
			String suppliercategoryCode) throws Throwable {
	
		return this.suppliercategoryDao.getSuppliercategoryByCode(suppliercategoryCode);
	}


	public List<PBaseAssistantmaterialSuppliercategory> getAssistantmaterialSuppliercategoryByCodeAndName(
			String suppliercategoryCode, String suppliercategoryName)
			throws Throwable {
			return this.suppliercategoryDao.getSuppliercategoryByCodeAndName(suppliercategoryCode, suppliercategoryName);
	}

	public List<PBaseAssistantmaterialSuppliercategory> getAssistantmaterialSuppliercategoryByName(
			String suppliercategoryName) throws Throwable {
		
		return this.suppliercategoryDao.getSuppliercategoryByName(suppliercategoryName);
	}

	/**
	 * 修改供应商类别信息
	 * @throws Throwable 
	 */
	@Override
	public void updateAssistantmaterialSuppliercategory(
			PBaseAssistantmaterialSuppliercategory suppliercategoryModel)
			throws Throwable {
//		try {
//			PBaseAssistantmaterialSuppliercategory asi = suppliercategoryDao.getSuppliercategoryById(suppliercategoryModel.getSupplierCategoryId());
//			if((suppliercategoryModel.getSupplierCategoryCode().trim().equals(asi.getSupplierCategoryCode().trim())) && (suppliercategoryModel.getSupplierCategoryName().trim().equals(asi.getSupplierCategoryName().trim())) ){	
//				this.suppliercategoryDao.updateSuppliercategory(suppliercategoryModel);
//		
//				}
//			else{
//				 if(suppliercategoryModel.getSupplierCategoryCode().trim().equals(asi.getSupplierCategoryCode().trim())){
//					 if(suppliercategoryDao.isSameName(suppliercategoryModel.getSupplierCategoryName())){
//						 throw new PHException("供应商分类名称"+suppliercategoryModel.getSupplierCategoryName()+"已经存在");
//					 }
//					 else{
//						 suppliercategoryDao.updateSuppliercategory(suppliercategoryModel);
//						
//					 }
//					 
//				 }
//				 else if(suppliercategoryModel.getSupplierCategoryName().trim().equals(asi.getSupplierCategoryName().trim())){
//					 if(suppliercategoryDao.isSameCode(suppliercategoryModel.getSupplierCategoryCode())){
//						 throw new PHException("供应商分类代码"+suppliercategoryModel.getSupplierCategoryCode()+"已经存在");
//					 }
//					 else{
//						 suppliercategoryDao.updateSuppliercategory(suppliercategoryModel);
//						
//					 }
//				 }
//				 else{
//					 if(suppliercategoryDao.isSameName(suppliercategoryModel.getSupplierCategoryName())){
//						 throw new PHException("供应商分类名称"+suppliercategoryModel.getSupplierCategoryName()+"已经存在");
//					 }
//					 else if(suppliercategoryDao.isSameCode(suppliercategoryModel.getSupplierCategoryCode())){
//						 throw new PHException("供应商分类代码"+suppliercategoryModel.getSupplierCategoryCode()+"已经存在");
//					 }
//					 else{
//						 suppliercategoryDao.updateSuppliercategory(suppliercategoryModel);
//						
//					 }
//				 }
//				
//			}
//			
//		} 
//		catch (SQLException e) {
//			throw new PHException("更新供应商分类异常");
//		}
		suppliercategoryDao.updateSuppliercategory(suppliercategoryModel);
	}

	/**
	 * @return the suppliercategoryDao
	 */
	public PBaseAssistantmaterialSuppliercategoryDao getSuppliercategoryDao() {
		return suppliercategoryDao;
	}

	/**
	 * @param suppliercategoryDao
	 *            the suppliercategoryDao to set
	 */
	public void setSuppliercategoryDao(
			PBaseAssistantmaterialSuppliercategoryDao suppliercategoryDao) {
		this.suppliercategoryDao = suppliercategoryDao;
	}

	/**
	 * @return the suppliercategoryList
	 */
	public List<PBaseAssistantmaterialSuppliercategory> getSuppliercategoryList() {
		return suppliercategoryList;
	}

	/**
	 * @param suppliercategoryList
	 *            the suppliercategoryList to set
	 */
	public void setSuppliercategoryList(
			List<PBaseAssistantmaterialSuppliercategory> suppliercategoryList) {
		this.suppliercategoryList = suppliercategoryList;
	}

	/**
	 * @return the suppliercategoryModel
	 */
	public PBaseAssistantmaterialSuppliercategory getSuppliercategoryModel() {
		return suppliercategoryModel;
	}

	/**
	 * @param suppliercategoryModel
	 *            the suppliercategoryModel to set
	 */
	public void setSuppliercategoryModel(
			PBaseAssistantmaterialSuppliercategory suppliercategoryModel) {
		this.suppliercategoryModel = suppliercategoryModel;
	}

}
